package durak.server.control;

import java.util.Scanner;


/**
 * Server class holds the main - which starts a new Server2ClientsCommunication
 * with given parameters: port#, amount of human players, amount of auto players
 */

public class Server {

	private Server2ClientsCommunication commObject;

	public Server(int human, int auto, int isXML, String xmlPath) throws Throwable {
		int cTosPortNumber = 1234;
		commObject = new Server2ClientsCommunication(cTosPortNumber, human, auto, isXML, xmlPath);

	}

	public static void main(String args[]) throws Throwable {

		int choice, human, auto;
		String xmlPath=null, xsdPath;
		ReadFromXmlFile xmlFile;

		Scanner scanner = new Scanner(System.in);

		System.out.println("Hello ! Welcome to Durak!");
		System.out.println("Please choose how to initialize the game");
		System.out.println("Choose (1) to initialize manually (default)");
		System.out.println("Choose (2) to initialize from an XML file");
		try {
			choice = Integer.parseInt(scanner.nextLine());
		} catch (NumberFormatException e) {
			choice = 1;
		}

		if (choice == 1) {
			System.out.println("Please Enter how many Human players will play ( Max is 4) ");
			human = Integer.parseInt(scanner.nextLine());
			System.out.println("Please Enter how many Computer players will play ( Max is 4) ");
			auto = Integer.parseInt(scanner.nextLine());
			Server server = new Server(human, auto, choice,xmlPath);
		} else if (choice == 2) {
			System.out.println("Please enter the path to the XML file");
			System.out.println("Please enter the path to the XSD file");
			xmlPath = scanner.nextLine();
			xsdPath = scanner.nextLine();
			xmlFile = new ReadFromXmlFile();
			if (xmlFile.validateXml(xmlPath, xsdPath) == true) {
				xmlFile.parseXmlFile(xmlPath);
				Server server = new Server(xmlFile.numOfHumanPalyers(), xmlFile.numOfAutoPalyers(), choice,xmlPath);
			} else {
				System.out.println("We cant read from the XML, Please fix it yourself !:)");
			}

		}

	}
}
